package com.lz.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.lz.form.UploadItemDTO;
import com.lz.service.UploadItemService;
import com.lz.util.PropertyReader;

public class AdminSearchAction extends DispatchAction {

    String forward = "RESULT";
    
    public static final int DISPLAYCOUNT=Integer.parseInt(PropertyReader.getConfigProperty("displaycount"));

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
       
	UploadItemDTO uform = (UploadItemDTO) form;
        HttpSession session=request.getSession(true);
        
        String orderby=request.getParameter("orderby");
        if(orderby!=null){
        	forward="CUSTOMERRESULT";
         }
        else{
        	orderby="lastupdate";
        	forward= "RESULT";
        }
        
        
        
        uform.setOrderby(orderby);
        uform.setForward(forward);
        ArrayList list = UploadItemService.getSearchResult(uform,orderby,"0",""+DISPLAYCOUNT);
        if(list.size()==0){
    	request.setAttribute("message","No records found matching the search criteria");
    	return mapping.findForward("MESSAGE");
        }
        
        uform.setShopid("1");
        
        
        uform.setImageList(list);
        request.setAttribute("pagenumber","1");
        session.setAttribute("queryparams",uform);
        
              
        return mapping.findForward(forward);
    }

}
